<?php
    class Civilite {
        //Alias sur table : civ
        public $id_civilite;
        public $libelle;
        public $diminutif;
        public $valide;
		
        //Constructeur complet
        public function __construct($id_civilite, $libelle, $diminutif, $valide) {
            $this->setId($id_civilite);
            $this->setLibelle($libelle);
            $this->setDiminutif($diminutif);
            $this->setValide($valide);
        }

        //Retourne le libellé de l'objet Civilite
        //Paramètre : aucun
        //Retourne (String)
        public function __toString() {
            return $this->libelle;
        }
        
        //Récupère tout les objets Civilite valide
        //Paramètre : OPTIONNEL (Booléen)valide
        //Retourne collection de Civilite
        public static function getCivilites($valide = true) {
            $sql =  'SELECT
                        civ.id_civilite as civid_civilite, civ.libelle as civlibelle, civ.diminutif as civdiminutif, civ.valide as civvalide
                    FROM civilite civ';
            if($valide) {
                $sql .= ' WHERE
                            civ.valide = 1';
            }
            $sql .= ' ORDER BY civ.libelle';
            $tabRetour = array();
            $ps = Db::Execute($sql, true);
            foreach($ps as $p) {
                $tabRetour[] = new Civilite($p['civid_civilite'], $p['civlibelle'], $p['civdiminutif'], $p['civvalide']);
            }
            return $tabRetour;
        }
        
        //Crée un objet Civilite grâce à son ID
        //Paramètre : (int)id
        //Retourne (Civilite)
        public static function rechercheCivilite($id) {
            $sql =  'SELECT
                        civ.id_civilite as civid_civilite, civ.libelle as civlibelle, civ.diminutif as civdiminutif, civ.valide as civvalide
                    FROM civilite civ
                    WHERE
                        civ.id_civilite = '.intval($id);
            $ps = Db::Execute($sql, true);
            foreach($ps as $p) {
                return new Civilite($p['civid_civilite'], $p['civlibelle'], $p['civdiminutif'], $p['civvalide']);
            }
            return null;
        }
		
        //GETTERS ET SETTERS
        public function getId() {return $this->id_civilite;}
        public function getLibelle() {return $this->libelle;}
        public function getDiminutif() {return $this->diminutif;}
        public function getValide() {return $this->valide;}

        public function setId($temp) {$this->id_civilite = intval($temp);}
        public function setLibelle($temp) {$this->libelle = $temp;}
        public function setDiminutif($temp) {$this->diminutif = $temp;}
        public function setValide($temp) {$this->valide = intval($temp);}
    }

?>